package com.qiall.fileutil;


import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class FileInfoUtil {

    /**
     * 如果文件不存在 或者 目标位置是文件夹则返回 0
     * @return bytes
     */
    public static long getFileLength(String filePath) {
        File file = new File(filePath);
        if (!file.exists()) {
            return 0;
        }
        if (file.isFile()) {
           return file.length();
        }
        return 0;
    }

    public static void copyFilesToTargetDir(String targetDir, List<String> files){
        for(String filePath:files){
            File file=new File(filePath);
            try {
                FileUtils.copyFile(file,new File(targetDir+file.getName()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void copy() {
        List<String> paths=new ArrayList<>();
        paths.add("E:\\git\\qiall-framework\\qiall-business\\project-manage\\project-ability\\target\\project-ability-1.0-SNAPSHOT.jar");
        paths.add("E:\\git\\qiall-framework\\qiall-oms\\oms-client\\target\\oms-client-1.0-SNAPSHOT.jar");
        paths.add("E:\\git\\qiall-framework\\qiall-user\\user-ability\\target\\user-ability-0.0.1-SNAPSHOT.jar");
        copyFilesToTargetDir("D:\\software\\tmp\\ability-jar\\",paths);
    }

}
